<?php
    $this->headTitle('Ticket details');
    $this->headScript()->appendFile('/js/BizSense/Crud.js');   
    $ticket = $this->ticket;
    $acl = $this->acl;    
?>

<h2>Tickets details</h2>

<?php if  ($acl->isAllowed($this->currentUser, 'access ticket pages')): ?>
<a href="<?php echo $this->url(
        array(
            'module' => 'ticket',
            'controller' => 'index',
            'action' => 'edit',
            'ticket_id' => $this->escape($ticket['ticket_id']),
        ), 'default', true
    ); ?>">Edit</a> |
<?php endif; ?>

<?php if  ($acl->isAllowed($this->currentUser, 'access ticket pages')): 
    $deleteUrl = $this->url(
                    array(
                        'module' => 'ticket',
                        'controller' => 'index',
                        'action' => 'delete',
                        'ticket_id' =>$this->escape($ticket['ticket_id'])
                    )
                );
                echo $this->deleteButton($deleteUrl); 
 endif; ?>

<table class="data_table">
    <tr>
        <td>Title</td>
        <td><?php echo $this->escape($ticket['title']); ?></td>
    </tr>
    <tr>
        <td>Description</td>
        <td><?php echo $this->escape($ticket['description']); ?></td>
    </tr>
    <tr>
        <td>Contact</td>
        <td><?php echo $this->contactLinkById(
                    $this->escape($ticket['contact_id'])); ?></td>
    </tr>
    <tr>
        <td>Status</td>
        <td><?php echo $this->escape($ticket['ticket_status']); ?></td>
    </tr>

</table>

<h2>Comments</h2>
<?php
    $comments = $this->ticketComments;
?>
<table class="data_table">
    <?php foreach ($comments as $comment): ?>
        <tr>
            <td>at <?php echo 
                 $this->escape($this->timestampToHuman($comment['created'])); ?>
                by <?php
                        if ($comment['created_by_type'] == 
                            Core_Model_Ticket_Comment::COMMENT_POSTER_TYPE_CONTACT) {
                            echo $this->contactLinkById($ticket['contact_id']); 
                        } else {
                            echo $this->userLinkById($comment['user_id']); 
                        }
                    ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $this->escape($comment['title']); ?></td>
        </tr>
        <tr>
            <td><?php echo $this->escape($comment['description']); ?></td>
        </tr>

    <?php endforeach; ?>
</table>
<p>
    Create a new comment
</p>
<div id="form">
<?php 
    echo $this->message;
    echo $this->form; 
?>
</div>
<div class="div_clear"></div>
